//
//  LMQQFrame.m
//  15qq
//
//  Created by apple on 15/8/4.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "LMQQFrame.h"
#import "LMQQ.h"
@implementation LMQQFrame

// 计算文本的大小
- (CGSize)sizeWithText:(NSString *)text maxSize:(CGSize)maxSize fontSize:(CGFloat)fontSize
{
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
}


- (void)setQq:(LMQQ *)qq
{
   
    _qq =qq;
    //设置时间
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGFloat margin = 10;
    CGFloat timeX = 0;
    CGFloat timeY = 10;
    CGFloat timeW = rect.size.width;
    CGFloat timeH = 50;
    if (!_qq.isHiddenTime) {
            _timeFrame = CGRectMake(timeX, timeY, timeW, timeH);
    }

    
    //设置头像
    
    CGFloat iconY = CGRectGetMaxY(_timeFrame)+margin;
    CGFloat iconW = 40;
    CGFloat iconH = 40;
    CGFloat iconX;
    if (qq.type == 0 ) {
        iconX = rect.size.width - iconW -margin;
    }else
    {
        iconX= margin;
    }
    
    _iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    
    //文字
    CGFloat textY = CGRectGetMaxY(_timeFrame)+margin;
    CGSize  textsize = [self sizeWithText:qq.text maxSize:CGSizeMake(200, CGFLOAT_MAX)
                                 fontSize:13];
    
    CGSize buttonsize = CGSizeMake(textsize.width+15*2, textsize.height+15*2);
    CGFloat textX;
    if (qq.type == 0 ) {
        textX = iconX-margin-buttonsize.width;
    }else
    {
        textX= margin + iconW + margin;
    }
    CGFloat textW = buttonsize.width;
    CGFloat textH = buttonsize.height;
    
    _textFrame = CGRectMake(textX, textY, textW, textH);
    
    if (CGRectGetMaxY(_textFrame)>CGRectGetMaxY(_iconFrame)) {
        _rowHeight  = CGRectGetMaxY(_textFrame)+margin;
    }
    else
    {
         _rowHeight  = CGRectGetMaxY(_iconFrame)+margin;
    }
    
    
    
    
}
@end
